﻿using Coldairarrow.Business;
using Coldairarrow.Entity;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Orderweb
{
    [Route("/Orderweb/[controller]/[action]")]
    public class BTB_OrdersController : BaseApiController
    {
        #region DI

        public BTB_OrdersController(IOrder_DecimalBusiness order_DecimalBus, IOrder_MasterBusiness order_MasterBus)
        {
            _order_DecimalBus = order_DecimalBus;
            _order_MasterBus = order_MasterBus;
        }

        private IOrder_DecimalBusiness _order_DecimalBus { get; }
        private IOrder_MasterBusiness _order_MasterBus { get; }

        #endregion DI

        /// <summary>
        /// 生成订单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OrderNum> AddOrderAsync(OrderDto dto)
        {
            //var validator = new OrderValidator();
            //var validationResult = validator.Validate(dto);

            //if (!validationResult.IsValid)
            //{
            //    return BadRequest(validationResult.Errors.First().ErrorMessage);
            //}
            return await _order_MasterBus.AddOrderAsync(dto);
        }

        /// <summary>
        /// 生成订单
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OrderNum> AddOrderTwo(SetOrderDto dto)
        {
            return await _order_MasterBus.SetToOrderAsync(dto);
        }

        /// <summary>
        /// 后台——修改订单地址
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task ChangeOrderAddressInfo(ChangeAddressInfoDTO input)
        {
             await _order_MasterBus.ChangeAddressInfo(input);
        }

        /// <summary>
        /// 前台——积分商品兑换
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OrderNum> SetPointGoodOrder(PointOrderDto dto)
        {
            return await _order_MasterBus.PointGoodOrderAsync(dto);
        }

        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="canncl"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task CancelOrderAsync(CannclOrder canncl)
        {
            await _order_MasterBus.CancelOrderAsync(canncl);
        }

        /// <summary>
        /// 获取订单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<OrderProducts> GetTheOrderData(OrderProducts input)
        {
            return await _order_MasterBus.GetTheOrderData(input);
        }

        /// <summary>
        /// 获取订单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<OrderProducts>> GetOrderData(PageInput<OrderProducts> input)
        {
            return await _order_MasterBus.GetOrderData(input);
        }
      
        /// <summary>
        /// 统计(前端统计)
        /// </summary>
        /// <returns></returns>
        [ HttpGet]
        public async Task<List<Statistics>> GetStatistics()
        {
            return await _order_MasterBus.GetStatistics();
        }

        /// <summary>
        /// 更新数据（订单状态）
        /// </summary>
        /// <param name="input">订单id信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task ChangeOrderInvoiceState(IdInputDTO input)
        {
            await _order_MasterBus.ChangeOrderInvoiceStateAsnyc(input);
        }

        [HttpPost]
        public async Task UpdateDataTwo(Order_Master data)
        {
            await _order_MasterBus.UpdateDataTwoAsync(data);
        }

        /// <summary>
        /// 后台——订单发货接口
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SendTheOrder(ToSendOrderDTO data)
        {
            await _order_MasterBus.SendOrderAsync(data);
        }

        /// <summary>
        /// 获待我的评论列表（DATA0：0待评论，DATA0:1评论完成）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<PageResult<Order_Decimal>> GetDataOver(PageInput<Order_Decimal> input)
        {
           return await _order_MasterBus.GetDataOver(input);
        }

        /// <summary>
        /// 获待我的评论（已评价、未评价）统计
        /// </summary>
        /// <returns></returns>

        [HttpPost]
        public async Task<object> GetOverSumData()
        {
            return await _order_MasterBus.GetOverSum();
        }

        [HttpPost]
        public async Task<string> GetOrderExploreFile(Order_DtoTwo input)
        {
            return await _order_MasterBus.GetOrderExploreFile(input);
        }

    }
}